package com.example.dbadaptertest;

import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

/**
 * This program adds entries to the database, then pulls them out and uses them
 * to populate a ListView.
 * 
 * @author Hanly De Los Santos (http://hdelossantos.com)
 * 
 */
public class DBAdapterTest extends ListActivity
{
	private ArrayList<String> queryString;
	private DatabaseQuery query;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		query = new DatabaseQuery(this);

		// Populate the database
		query.appendData("Title", "Row One");
		query.addRow();
		query.appendData("Title", "Row Two");
		query.addRow();

		// Pull the data from the database
		queryString = query.getData(new String[]
		{ "Title" }, null, null, null, null, "Title", " ASC");
		try
		{
			query.destroy();
		} catch (Throwable e)
		{
			e.printStackTrace();
		}

		// Set the ListView
		setListAdapter(new ArrayAdapter<String>(this,	android.R.layout.simple_list_item_1, queryString));
		getListView().setTextFilterEnabled(true);

	}
}